<!-- 查询商品优惠券信息 -->
<template>
    <div>
        <div class="table-page-search-wrapper">
            <a-form layout="inline">
                <a-row :gutter="48">
                    <a-col :md="8" :sm="24">
                        <a-form-item label="订单号">
                            <a-input v-model="orderCode" allow-clear placeholder="请输入订单号" />
                        </a-form-item>
                    </a-col>
                    <a-col :md="8" :sm="24">
                        <a-form-item label="评论是否有图片">
                            <a-select v-model="isPicture" placeholder="请选择" allowClear @change="getData()">
                                <a-select-option v-for="(item,i) in isPictureList" :key="i" :value="item.id">{{item.name}}</a-select-option>
                            </a-select>
                        </a-form-item>
                    </a-col>
                    <a-col :md="8" :sm="24">
                        <a-form-item label="是否有追评">
                            <a-select v-model="isExtra" placeholder="请选择" allowClear @change="getData()">
                                <a-select-option v-for="(item,i) in isExtraList" :key="i" :value="item.id">{{item.name}}</a-select-option>
                            </a-select>
                        </a-form-item>
                    </a-col>
                    <a-col :md="16" :sm="24">
                        <a-form-item label="日期">
                            <a-range-picker v-model="dateValue" @change="dateChange"/>
                        </a-form-item>
                    </a-col>
                    <a-col :md="8" :sm="24">
                        <a-form-item >
                            <a-button style="margin-right: 20px" type="primary" @click="getData()">查询</a-button>
                        </a-form-item>
                    </a-col>
                </a-row>
            </a-form>
        </div>

        <a-table rowKey="id" :loading="isload" :columns="columns" bordered :data-source="dataList" @change="handleTableChange" :pagination="{ pageSize: size, total: total ,showSizeChanger: true}" size="small" :scroll="{ x: 1500, }">
            <div slot="userId" slot-scope="userId,record">
                <div>{{userId}}/{{record.phone}}</div>
            </div>
            <div slot="imageUrl" slot-scope="imageUrl">
                <div v-if="imageUrl">
                    <!-- <div v-for="item in imageUrl.split(',')" :key="item">
                        <img style="width: 120px;height: 60px;margin-right: 10px;display: inline-block;" :src="item" alt="">
                    </div> -->
                    <img @click="showImg(imageUrl)" style="width: 120px;height: 60px;margin-right: 10px;display: inline-block;" :src="imageUrl.split(',')[0]" alt="">
                </div>
                <div v-else>-</div>
            </div>
            <div slot="goodsEvaluationCommentReplyDTOList" slot-scope="goodsEvaluationCommentReplyDTOList">
                <div v-for="item in goodsEvaluationCommentReplyDTOList" :key="item.id">
                    <div>
                        <span>{{item.userName}}</span>
                        <span v-if="item.replyUserId">回复 {{item.replyUserName}}</span><span style="color: blue">：</span>{{item.content}}
                    </div>
                </div>
            </div>
            <template slot="operation" slot-scope="text, record">
                <div class="editable-row-operations">
                    <a-button type="link" @click="update(record)">回复</a-button>
                    <a-popconfirm
                        title="是否确认删除当前评论?"
                        ok-text="Yes"
                        cancel-text="No"
                        @confirm="del(record)"
                    >
                        <a-button type="link" class="errorColor">删除评论</a-button>
                    </a-popconfirm>
                    <!-- <a-popconfirm
                        title="是否确认删除当前数据?"
                        ok-text="Yes"
                        cancel-text="No"
                        @confirm="del(record)"
                    >
                        <a-button type="link">删除</a-button>
                    </a-popconfirm> -->
                </div>
            </template>
        </a-table>

        <!-- 商家回复 -->
        <a-modal
            title="商家回复"
            :visible="visible"
            :confirm-loading="confirmLoading"
            @ok="handleOk"
            @cancel="visible = false"
            >
            <div>
                <a-form :label-col="{ span: 6 }" :wrapper-col="{ span: 17 }">
                    <a-form-item label="回复用户">
                        <a-select v-model="item.commentId" placeholder="请选择" allowClear @change="getData()">
                            <a-select-option v-for="(item,i) in commentIdList" :key="i" :value="item.id">{{item.userName}}：{{item.content}}</a-select-option>
                        </a-select>
                    </a-form-item>
                    <a-form-item label="回复内容">
                        <a-input v-model="item.content" placeholder="请输入回复内容" allow-clear></a-input>
                    </a-form-item>
                </a-form>
            </div>
        </a-modal>

        <!-- 表格图片预览 -->
        <a-modal :visible="previewImgVisible" :footer="null" @cancel="previewImgVisible = false">
            <a-carousel autoplay dots-class="slick-dots slick-thumb" style="margin-bottom:60px">
                <div v-for="(img,i) in showImgs" :key="i">
                    <img :src="img" alt=""/>
                </div>
                <a slot="customPaging" slot-scope="props">
                    <img :src="getImgUrl(props.i)" />
                </a>
            </a-carousel>
        </a-modal>
    </div>


</template>

<script>
import { columns } from './table'
import { queryGoodsEvaluationInfo , updateGoodsEvaluationCommentReply , updateGoodsEvaluationInfo } from '@/api/newMall'
export default {
    data () {
        return {
            brandId: this.global.brandId,
            brandList: [],
            page: 1,
            size: 10,
            total: 0,
            dataList: [],
            columns,
            isload: false,
            orderCode: '', // 订单号
            startTime: '',
            endTime: '',
            dateValue: [],
            isPicture: undefined, // 是否有图片
            isPictureList: [
                { id: 0, name: '没有图片'},
                { id: 1, name: '有图片'},
            ],
            isExtra: undefined, // 是否追评
            isExtraList: [
                { id: 0, name: '没有'},
                { id: 1, name: '有追评'},
            ],
            status: undefined,
            statusList: [
                { id: 0, name: '未使用'},
                { id: 1, name: '已使用'},
                { id: 2, name: '已过期'},
            ],
            isload: false,
            colors: ['blue','purple','cyan','green','orange','red','pink','brown','indigo','lime','purple','teal','yellow','amber'],
            visible: false,
            confirmLoading: false,
            item: {
                evaluationId: '',
                content: '',
                commentId: undefined,
            },
            commentIdList: [],
            previewImgVisible: false,
            showImgs: [],
        }
    },
    async created(){
        try {
            this.getData()
        } catch (error) {
            this.$notification['error']({
                message: '提示',
                description: '网路丢失，请稍后再试！',
                duration: 8,
            })
        }
    },
    methods: {
        // 查询产品详情信息配置
        getData(){
            var _this = this
            _this.isload = true
            const params = {
                brandId: _this.brandId,
                isPicture:_this.isPicture,
                isExtra: _this.isExtra,
                orderCode: _this.orderCode,
                startTime: _this.startTime,
                endTime: _this.endTime,
                page: _this.page - 1,
                size: _this.size,
            }
            queryGoodsEvaluationInfo(params)
            .then(res=>{
                _this.isload = false
                if(res.success){
                    _this.dataList = res.data.content
                    _this.total = res.data.totalElements
                    console.log(_this.dataList,'dataList')
                }else{
                    _this.$notification['error']({
                        message: '提示',
                        description: res.errMessage,
                        duration: 8,
                    })
                }
            })
        },
        // 分页
        handleTableChange(pagination, filters, sorter) {
            console.log(pagination);
            this.page = pagination.current;
            this.size = pagination.pageSize;
            this.getData()
        },
        dateChange(date,dateString){
            this.startTime = dateString[0];
            this.endTime = dateString[1];
            this.getData();
        },
        // 添加优惠券
        add(){
            this.item.id = ''
            this.item.userId = ''
            this.item.name =  ''
            this.item.type = '1'
            this.item.amount = ''
            this.item.requirement = ''
            this.item.validTime = ''
            this.item.remarks = ''
            this.visible = true;
        },
        // 修改
        update(item){
            // this.item = JSON.parse(JSON.stringify(item))
            this.item.evaluationId = item.id;
            this.commentIdList = item.goodsEvaluationCommentReplyDTOList;
            this.item.content = '';
            this.item.commentId = undefined;
            this.visible = true
        },
        // 确认发放
        handleOk(){
            let _this = this;
            if(_this.item.content == ''){
                _this.$message.warning('请输入回复内容');
                return
            }
            const params = {
                'evaluationId': _this.item.evaluationId,
                'content': _this.item.content,
                'commentId': _this.item.commentId,
            }
            _this.confirmLoading = true;
            updateGoodsEvaluationCommentReply(params)
            .then(res => {
                _this.confirmLoading = false;
                if(res.success){
                    _this.$notification['success']({
                        message: '提示',
                        description: '回复成功',
                        duration: 8,
                    })
                    _this.visible = false;
                    _this.getData();
                }else{
                    _this.$notification['error']({
                        message: '提示',
                        description: res.errMessage,
                        duration: 8,
                    })
                }
            })
        },
        // 删除评论
        del(item){
            let _this = this
            const params = {
                'id':item.id,
                'grade': item.grade,
                'content': item.content,
                'descriptionConsistent': item.descriptionConsistent,
                'logisticsServices': item.logisticsServices,
                'serviceAttitude': item.serviceAttitude,
                'isDelete':1,
            }
            updateGoodsEvaluationInfo(params)
            .then(res=>{
                if(res.success){
                    _this.getData()
                    _this.$notification['success']({
                        message: '提示',
                        description: '删除成功',
                        duration: 8,
                    })
                }else{
                    _this.$notification['error']({
                        message: '提示',
                        description: res.errMessage,
                        duration: 8,
                    })
                }
            })
        },
        // 预览图片
        showImg(imgs){
            if(imgs){
                this.showImgs = imgs.split(',')
                console.log(this.showImgs,'imgs')
                this.previewImgVisible = true
            }
        },
        getImgUrl(i){
            return this.showImgs[i]
        },
    }
}

</script>
<style scoped>
.imgUrl{
    width: 180px;
    height: 100px;
}
.ant-carousel >>> .slick-slide img {
    text-align: center;
    height: 300px;
    line-height: 300px;
    background: #364d79;
    overflow: hidden;
    width: 100%;
}
.ant-carousel >>> .slick-thumb {
  bottom: -15px;
}
.ant-carousel >>> .slick-thumb li {
  width: 60px;
  height: 45px;
}
.ant-carousel >>> .slick-thumb li img {
  width: 100%;
  height: 100%;
  filter: grayscale(100%);
}
.ant-carousel >>> .slick-thumb li.slick-active img {
  filter: grayscale(0%);
}
</style>